#include "AX58100hw_spi.h"


uint8_t WR_CMD(uint8_t cmd)
{
    uint8_t retry = 0;

    /* Check if Tx buffer is empty */
    while (!LL_SPI_IsActiveFlag_TXE(SPI2)) 
    {
        retry++;
        if(retry > 200) return 0;
    }			  

    /* Write character in Data register.
    TXE flag is cleared by reading data in DR register */
    LL_SPI_TransmitData8(SPI2, cmd);
    retry = 0;

    /* Check if Rx buffer is not empty */
    while (!LL_SPI_IsActiveFlag_RXNE(SPI2)) 
    {
        retry++;
        if(retry > 200) return 0;
    }	  						    

    /* received byte from SPI lines. */
    return LL_SPI_ReceiveData8(SPI2);
}


 